473,432 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,432 software developers and data experts.

Cascading menus with Tk

Hi all,

I am new to Tk, or Python GUI programming and I seem to be stuck. I
have looked about for help with Tk GUIs, but everything seems so terse
or incomplete?? I have been mostly using the "Introduction to Tkinter"
by Fredrik Lundh
(http://www.pythonware.com/library/tk...tion/index.htm)

What I am trying to do is add cascading menus to a Tk menu widget like:

File
New...
---> Router
---> Firewall
Open
----
Exit

This seems simple enough, but I can't get it to work...the two
"add_cascade" methods (shown below), if used, run an endless loop that
is difficult to break:

mainWindow = Tk()
mainWindow.title("myApp")

# create a menu
menubar = Menu(mainWindow)
mainWindow.config(menu=menubar)

filemenu = Menu(menubar)
menubar.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New...")
filemenu.add_cascade(label="Router")
filemenu.add_cascade(label="Firewall")
filemenu.add_command(label="Open...", command = openFileDialog)
filemenu.add_separator()
filemenu.add_command(label="Exit", command = mainWindow.destroy)

helpmenu = Menu(menubar)
menubar.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="Online Help")
helpmenu.add_command(label="Help on the web")
helpmenu.add_separator()
helpmenu.add_command(label="About...", command = openAboutBox)

Any ideas??

Miki
Jul 19 '05 #1
3 3561
michelle wrote:
What I am trying to do is add cascading menus to a Tk menu widget like:

File
New...
---> Router
---> Firewall
Open
----
Exit
Just add the submenu with the "Router" and "Firewall" entries to the
filemenu in the same way you added the submenu with the "New", "Open", and
"Exit" entries to the menu bar:
mainWindow = Tk()
mainWindow.title("myApp")

# create a menu
menubar = Menu(mainWindow)
mainWindow.config(menu=menubar)

filemenu = Menu(menubar)
menubar.add_cascade(label="File", menu=filemenu)
new_menu = Menu(filemenu)
new_menu.add_command(label="Router")
new_menu.add_command(label="Firewall")
filemenu.add_cascade(label="New...", menu=new_menu)
filemenu.add_command(label="Open...", command = openFileDialog)
filemenu.add_separator()
filemenu.add_command(label="Exit", command = mainWindow.destroy)


Peter

Jul 19 '05 #2
michelle wrote:
Hi all,

I am new to Tk, or Python GUI programming and I seem to be stuck. I
have looked about for help with Tk GUIs, but everything seems so terse
or incomplete?? I have been mostly using the "Introduction to Tkinter"
by Fredrik Lundh
(http://www.pythonware.com/library/tk...tion/index.htm)

What I am trying to do is add cascading menus to a Tk menu widget like:

File
New...
---> Router
---> Firewall
Open
----
Exit

This seems simple enough, but I can't get it to work...the two
"add_cascade" methods (shown below), if used, run an endless loop that
is difficult to break:

mainWindow = Tk()
mainWindow.title("myApp")

# create a menu
menubar = Menu(mainWindow)
mainWindow.config(menu=menubar)

filemenu = Menu(menubar)
menubar.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New...")
I think you want these two options to be in a cascading menu like so:

newmenu = Menu(filemenu)
filemenu.add_cascade(label="New...", menu=newmenu)

newmenu.add_command(label="Router")
newmenu.add_command(label="Firewall")
filemenu.add_cascade(label="Router")
filemenu.add_cascade(label="Firewall")
filemenu.add_command(label="Open...", command = openFileDialog)
filemenu.add_separator()
filemenu.add_command(label="Exit", command = mainWindow.destroy)

helpmenu = Menu(menubar)
menubar.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="Online Help")
helpmenu.add_command(label="Help on the web")
helpmenu.add_separator()
helpmenu.add_command(label="About...", command = openAboutBox)

Any ideas??

Miki


Martin

Jul 19 '05 #3
Martin Franklin wrote:
michelle wrote:
Hi all,

I am new to Tk, or Python GUI programming and I seem to be stuck. I
have looked about for help with Tk GUIs, but everything seems so terse
or incomplete?? I have been mostly using the "Introduction to Tkinter"
by Fredrik Lundh
(http://www.pythonware.com/library/tk...tion/index.htm)

What I am trying to do is add cascading menus to a Tk menu widget like:

File
New...
---> Router
---> Firewall
Open
----
Exit

This seems simple enough, but I can't get it to work...the two
"add_cascade" methods (shown below), if used, run an endless loop that
is difficult to break:

mainWindow = Tk()
mainWindow.title("myApp")

# create a menu
menubar = Menu(mainWindow)
mainWindow.config(menu=menubar)

filemenu = Menu(menubar)
menubar.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New...")

I think you want these two options to be in a cascading menu like so:

newmenu = Menu(filemenu)
filemenu.add_cascade(label="New...", menu=newmenu)

newmenu.add_command(label="Router")
newmenu.add_command(label="Firewall")
filemenu.add_cascade(label="Router")
filemenu.add_cascade(label="Firewall")
filemenu.add_command(label="Open...", command = openFileDialog)
filemenu.add_separator()
filemenu.add_command(label="Exit", command = mainWindow.destroy)

helpmenu = Menu(menubar)
menubar.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="Online Help")
helpmenu.add_command(label="Help on the web")
helpmenu.add_separator()
helpmenu.add_command(label="About...", command = openAboutBox)

Any ideas??

Miki

Martin

Thank you, your code worked perfectly....

Miki
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Humpty Dumpty | last post by:
Hi folks, here's a challenge: I have a dynamically created cascading menu in Tkinter that can be quite large because it is created from a file. I tried using lazy creation so only the menu item...
7
by: Marci | last post by:
I found this script for cascading menus, however, I cannot reach the author to solve the bug I am having when I add a second menu to it. My problem is this: If I click on the first link, the...
1
by: Cindy Lee | last post by:
is it possible to have cascading menus like: http://www.cracky.net/JAVA/Navigation/cascading-menu.html With scrollbars added, so you can only see a few options at a time? On some of my options...
1
by: JMosey | last post by:
Not sure if this has been covered ( a google search came up pretty bare). I have a site that: - has multi-level cascading menus - floats center of the browser window - Will have fairly heavy...
1
by: Yavuz Bogazci | last post by:
hi, has someone a sample how to create cascading and database driven menues??? Help! I don't know where to begin! Thanks Yavuz Bogazci
5
by: MarkW | last post by:
I hope this is the correct place to post this: I am developing a web site for a e-commerce business I will be running. The site I'm setting up will be 50% store, 50% content. I'm not sure which...
1
by: arjun.zacharia | last post by:
Hi everyone, i want to implement a cascading menu in my application but do not want to reinvent the wheel. is there anybody here who might have written such stuff or could help me with somem...
1
by: support | last post by:
In dotNet, I want to have cascading pulldown menus. Hence, the items are: { a, b, cx, cy, cz, d}, but I don't want to show cx, cy, cz unless the user selected one of the c's. Does anyone know a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.